#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int N;
int b[10][10];
int f[10][10];
int ans = 0;

int main() {
    cin >> N;
    memset(b, 0, sizeof(b));
    memset(f, 0, sizeof(f));
    while (true) {
        int x, y, v;
        cin >> x >> y >> v;
        if (!x && !y && !v)
            break;
        else
            b[x - 1][y - 1] = v;
    }
    f[0][0] = b[0][0];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == 0 && j > 0)
                f[i][j] = f[i][j - 1] + b[i][j];
            else if (j == 0 && i > 0)
                f[i][j] = f[i - 1][j] + b[i][j];
            else
                f[i][j] = b[i][j] + max(f[i - 1][j], f[i][j - 1]);
        }
    }
    ans += f[N - 1][N - 1];

    int x = N - 1, y = N - 1;
    while (x > 0 && y > 0) {
        if (x == 0 || f[x][y] - f[x][y - 1] == b[x][y]) {
            y--;
            b[x][y + 1] = 0;
        } else if (y == 0 || f[x][y] - f[x - 1][y] == b[x][y]) {
            x--;
            b[x + 1][y] = 0;
        }
    }

    memset(f, 0, sizeof(f));
    f[0][0] = b[0][0];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == 0 && j > 0)
                f[i][j] = f[i][j - 1] + b[i][j];
            else if (j == 0 && i > 0)
                f[i][j] = f[i - 1][j] + b[i][j];
            else
                f[i][j] = b[i][j] + max(f[i - 1][j], f[i][j - 1]);
        }
    }
    ans += f[N - 1][N - 1];

    cout << ans;
}